﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DoctorManage.aspx.cs" Inherits="RegisterWeb.Manager.DoctorPersonalCenter.ManageDoctor" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/gray/easyui.css" rel="stylesheet"
        type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>


<script type="text/javascript">

    var url; //提交数据的路径
    var formId; //当天要提交的Form的编号
    var dialogId; //对话框的编号

    var successCallback = function (result) {
        alert(result);
        //result为请求处理后的返回值
        var result = eval('(' + result + ')');
        if (result.success) {
            $.messager.show({
                title: 'Success',
                msg: result.msg
            });
            $(dialogId).dialog('close');
            $('#dg').datagrid('reload');
        } else {
            $.messager.show({
                title: 'Error',
                msg: result.msg
            });
        }
    }

   $(function () {
       //预加载编辑框
       $("#addDoctor").dialog('refresh');
        $("#editDoctor").dialog({
            modal: true,
            "title": "编辑医生信息",
            width: 620,
            height: 550,
            href: 'EditDoctor.aspx'
        });
        $("#editDoctor").dialog('open').dialog('close');

        $('#dg').datagrid({

            onDblClickRow: function (rowIndex, rowData) {
                $('#editDoctor').dialog('open');
                //$('#edit').form('clear');
              $("#Departments_ID").combobox('setValue',rowData.Departments_IDValue);

                $('#Doctor_Name').val(rowData.Doctor_Name);

                $('#Doctor_Gender').combobox('setValue', rowData.Doctor_Gender);

                $('#Doctor_DateOfBirth').datebox('setValue',rowData.Doctor_DateOfBirth);
                $("#Doctor_Position").combobox('setValue', rowData.Doctor_PositionValue);
                $("#Doctor_Education").combobox('setValue',rowData.Doctor_EducationValue);
                $("#Doctor_Phone").val(rowData.Doctor_Phone);
                $("#Doctor_Email").val(rowData.Doctor_Email);
                $("#Doctor_Specialty").val(rowData.Doctor_Specialty);
                $("#Doctor_Resume").val(rowData.Doctor_Resume);
                $("#Doctor_Picture").val(rowData.Doctor_Picture);
                //     $('#edit').form('clear');
                url = 'ashx/DoctorHandler.ashx?action=edit&id=' + rowData.Doctor_ID//+'&Departments_IDValue=' + $('#Departments_ID').combobox('getValue') + '&Doctor_PositionValue=' + $('#Doctor_Position').combobox('getValue') + '&Doctor_Education=' + $('#Doctor_Education').combobox('getValue');
                formId = "#edit";
                dialogId = "#editDoctor";

            }
        });

    });
    //编辑医院部分
    function editDoctor() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $("#addDoctor").dialog('refresh');
            $('#editDoctor').dialog('open');
            // $('#edit').form('clear');
            //$("#City_ID").combobox('setValue', row.City_ID);
            $("#Departments_ID").combobox('setValue', row.Departments_IDValue);

            $('#Doctor_Name').val(row.Doctor_Name);

            $('#Doctor_Gender').combobox('setValue', row.Doctor_Gender);

            $('#Doctor_DateOfBirth').datebox('setValue',row.Doctor_DateOfBirth);
            $("#Doctor_Position").combobox('setValue', row.Doctor_PositionValue);
            $("#Doctor_Education").combobox('setValue', row.Doctor_EducationValue);
            $("#Doctor_Phone").val(row.Doctor_Phone);
            $("#Doctor_Email").val(row.Doctor_Email);
            $("#Doctor_Specialty").val(row.Doctor_Specialty);
            $("#Doctor_Resume").val(row.Doctor_Resume);
            $("#Doctor_Picture").val(row.Doctor_Picture);
            //      $('#edit').form('clear');
            url = 'ashx/DoctorHandler.ashx?action=edit&id=' + row.Doctor_ID;  //+ '&Departments_IDValue=' + $('#Departments_ID').combobox('getValue') + '&Doctor_PositionValue=' + $('#Doctor_Position').combobox('getValue') + '&Doctor_Education=' + $('#Doctor_Education').combobox('getValue') ;
            formId = "#edit";
            dialogId = "#editDoctor";

        }
        else {
            $.messager.alert("提示", "您没有选中任何行！");
        }
    }
    
    //添加医生部分
    function addDoctor() {
        $("#addDoctor").dialog('refresh');
        $("#addDoctor").dialog({
            modal: true,
            "title": "新建医生",
            width: 620,
            height: 550,
            href: 'AddDoctor.aspx'
        });
        $('#addDoctor').dialog('open');
        $('#add').form('clear');

        url = 'ashx/DoctorHandler.ashx?action=add';
        formId = "#add";
        dialogId = "#addDoctor";
    }
    function checkUser() {

        var row = $('#dg').datagrid('getSelected');
        $.post('ashx/DoctorHandler.ashx?action=checkUser', { action: 'checkUser', id: row.Doctor_ID }, function (data, status) {
            if (data == 'no') {
               $("#addDoctor").dialog('refresh');
            $("#addDoctor").dialog({
                modal: true,
                "title": "新建医生用户",
                width: 400,
                height: 300,
                href: '../SystemUserManager/AddDoctorUser.aspx'
            });
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#addDoctor').dialog('open');
                url = '../SystemUserManager/ashx/DoctorUserHandler.ashx?action=addDoctorUser&id=' + row.Doctor_ID;
                formId = "#addDoctorUs";
                dialogId = "#addDoctor";

            }
            else {
                $.messager.alert("提示", "您没有选中任何行！");

                  }
            }
            else {
                $.messager.alert("提示", "此医生已存在用户!","info");
            }
        });
    }
    
     //新建医生用户
    /*function addDoctorUser() {
        //checkUser();
       // if ($("#label").text()=="no") {
            $("#addDoctor").dialog('refresh');
            $("#addDoctor").dialog({
                modal: true,
                "title": "新建医生用户",
                width: 400,
                height: 300,
                href: '../SystemUserManager/AddDoctorUser.aspx'
            });
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#addDoctor').dialog('open');
                url = '../SystemUserManager/ashx/DoctorUserHandler.ashx?action=addDoctorUser&id=' + row.Doctor_ID;
                formId = "#addDoctorUs";
                dialogId = "#addDoctor";

            }
            else {
                $.messager.alert("提示", "您没有选中任何行！");

                  }
        }
        if($("#label").text()=="ok") {
            $("#addDoctor").dialog('refresh');
            $.messager.alert("提示", "此医生已存在用户!");
            
        }
    }
  
  */
   
    function saveInfo() {
        $(formId).form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: successCallback
        });
    }

    //  删除医院部分
    function deleteDoctor() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除提示', '确定要删除' + row.Doctor_Name + '吗', function (r) {
                if (r) {
                    $.post('ashx/DoctorHandler.ashx?action=delete', { id: row.Doctor_ID, action: 'delete' }, function (data, status) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload');
                            $.messager.show({
                                title: 'Success',
                                msg: '删除成功!'
                            });
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: '删除失败!'
                            });
                        }
                    });
                }
            });
        }
    }

    //验证医生用户昵称
    function check() {
        var value = $("#DoctorUser_UserName").val();
        if (value != "") {
            $.post('../SystemUserManager/ashx/DoctorUserHandler.ashx?action=check', { action: 'check', name: value }, function (data, status) {
                if (data == 'ok') {
                    $("#DoctorUser_UserName").val("");
                    $("#error").text("用户名" + value + "已存在！");
                }
                else {
                    $("#error").text("");
                }
            });
        }
    }
    //验证密码是否相同
    function checkPwd() {
        var DoctorUser_RePassword = $("#DoctorUser_RePassword").val();
        var DoctorUser_Password = $("#DoctorUser_Password").val();
        if (DoctorUser_RePassword != DoctorUser_Password) {
            $("#error1").text("两次密码不一致");
            $("#DoctorUser_RePassword").val("");
        }
        else {
            $("#error1").text("");
        }

    } 
</script>

</head>
<body>
    <form id="form1" >
 
    <div region="center" title="医生信息管理" >
<table id="dg" title="医生信息管理" class="easyui-datagrid" style="width:850px;height:550px"
			url="ashx/DoctorHandler.ashx?action=get"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true" 
            pageSize="20"
            >
            
		<thead>
			<tr>	<th field="Doctor_No" 

width="50">医生编号</th>

			<th field="Departments_ID" width="50">所在科室</th>
<th field="Doctor_ID"  width="10"  hidden="true">医生ID</th>
				<th field="Doctor_Name" width="50">姓名</th>
		         <th field="Doctor_Gender" width="50">性别</th>
                 <th field="Doctor_DateOfBirth" width="50" hidden="true">出生日期</th>
   
                 <th field="Doctor_Position" width="50">职称

</th>
                 <th field="Doctor_Education" width="50">教育程度

</th>
                 <th field="Doctor_Phone" width="35"  >联系电话</th>
                 <th field="Doctor_Email" width="60" >邮箱

</th>
 <th field="Doctor_Specialty" width="60" hidden="true">专长</th>
  <th field="Doctor_Resume" width="60" hidden="true">简历</th>
 <th field="Doctor_Picture" width="10" hidden="true">图片路径

</th> <th field="Doctor_AddTime" width="10" hidden="true">添加日期

</th>
<th field="Doctor_Recoder" width="10" hidden="true">上传者

</th>
			</tr>
		</thead>
	</table>

    <div id="toolbar" style="padding:5px;height:auto">
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addDoctor()">添加医生</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editDoctor()">编辑医院</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteDoctor()">删除医生</a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="checkUser()">创建账户</a>
                    
    </div>


			<div id="addDoctor" class="easyui-dialog" closed="true" buttons="#addDoctor-buttons" style="padding:10px 20px">
        	</div>
			<div id="addDoctor-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick='$("#addDoctor").dialog("close");'>关闭</a>
			</div>

            <div id="editDoctor" class="easyui-dialog" closed="true" buttons="#editDoctor-buttons" style="padding:10px 20px">
        	</div>
            <div id="editDoctor-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok"  onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick='$("#editDoctor").dialog("close");'>关闭</a>
			</div>

    </div>
       <label style="display:none" id="label"></label>
    </form>
</body>
</html>
